package gaml.testing;

import gaml.core.GamlConfig;
import gaml.error.GamlException;
import gaml.text.TextNodeBridge;
import gaml.text.YamlNodePrinter;
import gaml.text.YamlPrinterStore;
import gaml.text.YamlText;
import gaml.text.printer.EmptyNodePrinter;
import gaml.text.printer.MappingNodePrinter;
import gaml.text.printer.ScalarNodePrinter;
import gaml.text.printer.SequenceNodePrinter;
import gaml.yaml.MappingNode;
import gaml.yaml.ScalarNode;
import gaml.yaml.SequenceNode;
import gaml.yaml.ahchor.YamlAnchor;

import org.junit.Test;


public class SequenceNodePrinterTest {
	@Test
	public void testPrint () throws GamlException {
		SequenceNode node = new SequenceNode (null);
		node.setAnchor (new YamlAnchor ("seqanch", node)).setComment ("sequence node comment");
		
		MappingNode map = new MappingNode (node);
		map.setAnchor (new YamlAnchor ("mapanch", map)).setComment ("mapping node comment");
		
		map.addChild (new ScalarNode (map).setValue ("mapkey1"), new ScalarNode (map).setValue ("mapval1"));
		map.addChild (new ScalarNode (map).setValue ("mapkey2"), new ScalarNode (map).setValue ("mapval2"));
		
		node.addChild (new ScalarNode (node).setValue ("seqval1"));
		node.addChild (map);
		node.addChild (new ScalarNode (node).setValue ("seqval2"));
		
		YamlPrinterStore store = new YamlPrinterStore ((YamlNodePrinter) new EmptyNodePrinter (GamlConfig.getDefault ()));
		store.register (new ScalarNodePrinter (GamlConfig.getDefault ()));
		store.register (new MappingNodePrinter (store, GamlConfig.getDefault ()));
		store.register (new SequenceNodePrinter (store, GamlConfig.getDefault ()));
		
		System.out.println (new TextNodeBridge (new YamlText (), node).parseNode (store).getText ().getText ().trim ());
	}
}